package com.zh.config.rabbitmq;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * topic
 */
@Configuration
public class TopicRabbitConfig {
    // 绑定键
    public final static String MAN = "topic.man";
    public final static String WO_MAN = "topic.#";
    // 队列名称
    public final static String TEST_MAN_TOPIC_QUEUE = "test-man-topic-queue";
    public final static String TEST_WOMAN_TOPIC_QUEUE = "test-woman-topic-queue";
    // 交换机名称
    public final static String TEST_WOMAN_TOPIC_EXCHANGE = "test-topic-exchange";
    /**
     * MAN
     * @return
     */
    @Bean
    public Queue createManTopicQueue(){
        return new Queue(TEST_MAN_TOPIC_QUEUE,true);
    }
    /**
     * WOMAN
     * @return
     */
    @Bean
    public Queue createWomanTopicQueue(){
        return new Queue(TEST_WOMAN_TOPIC_QUEUE,true);
    }

    /**
     * topic 交换机
     * @return
     */
    @Bean
    public TopicExchange createTopicExchange(){
        return new TopicExchange(TEST_WOMAN_TOPIC_EXCHANGE,true,false);
    }

    /**
     * 绑定交换机和队列，,而且绑定的键值为topic.man
     * 这样只要是消息携带的路由键是topic.man,才会分发到该队列
     * @return
     */
    @Bean
    public Binding createTopicBinding(){
        return BindingBuilder.bind(createManTopicQueue()).to(createTopicExchange()).with(MAN);
    }

    /**
     * 绑定交换机和队列，,而且绑定的键值为topic.#
     * 这样只要是消息携带的路由键是topic开头,才会分发到该队列
     * @return
     */
    @Bean
    public Binding createTopicBinding2(){
        return BindingBuilder.bind(createWomanTopicQueue()).to(createTopicExchange()).with(WO_MAN);
    }
}
